package com.youlai.boot.modules.exhibition.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.boot.modules.exhibition.converter.ExhibitionConverter;
import com.youlai.boot.modules.exhibition.mapper.ExhibitionMapper;
import com.youlai.boot.modules.exhibition.model.Exhibition;
import com.youlai.boot.modules.exhibition.model.ExhibitionForm;
import com.youlai.boot.modules.exhibition.model.ExhibitionVO;
import com.youlai.boot.modules.exhibition.model.ExhibitionPageQuery;
import com.youlai.boot.modules.exhibition.service.ExhibitionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ExhibitionServiceImpl extends ServiceImpl<ExhibitionMapper, Exhibition> implements ExhibitionService {

    private final ExhibitionConverter exhibitionConverter;

    @Override
    public Page<ExhibitionVO> getExhibitionPage(ExhibitionPageQuery query) {
        Page<ExhibitionVO> page = new Page<>(query.getPageNum(), query.getPageSize());
        return baseMapper.getExhibitionPage(page, query);
    }

    @Override
    public ExhibitionVO getExhibitionById(Long id) {
        Exhibition exhibition = this.getById(id);
        return exhibitionConverter.toVO(exhibition);
    }

    @Override
    public Long saveExhibition(ExhibitionForm form) {
        Exhibition exhibition = exhibitionConverter.toEntity(form);
        this.save(exhibition);
        return exhibition.getId();
    }

    @Override
    public void updateExhibition(ExhibitionForm form) {
        Exhibition exhibition = exhibitionConverter.toEntity(form);
        this.updateById(exhibition);
    }

    @Override
    public boolean deleteExhibition(Long id) {
        return this.removeById(id);
    }
}